*****
/*
The raw Gallup data is not publicly available for privacy reasons, but the smaller replication file created below is. As such this code is for 
illustrative purposes only.
*/
*****


use "[RAW Gallup DATA]", clear

keep RACE hisp multiracial  parent_age dad married sole_caretaker bio_parent parent_adopt step_parent foster_parent grandparent family_mem other_relationship  hhinc inc_bel60 inc_abv175 parent_hs_less parent_some parent_ba parent_grad asian black hispanic multi white hhinc weight comp_mental_health RACE male age_group_num1 age_group_num2 age_group_num3 age_group_num4 age_group_num5 age_group_num6 age_group_num7 age_group_num8 age_group_num9 age child_weight ///
B11C B11F B10_1 B10_2 B10_3 B10_4 B10_5 B10_6 B10_7 B10_9 B10_10 B10_11 B10_12 B10_13 B10_14 B10_15 B10_16 B10_17 B10_18 B10_19 B10_21 ///
C22_needs C20_alcohol C21_angry  C23_left C23a_rejection ///
YC22_needs YC20_alcohol YC21_angry  YC23_left YC23a_rejection ///
NC20_alcohol	NC21_angry	NC23_left	NC23a_rejection	C24_safety	REB11A	B11B	C19_parent_love	B6_overall_parent_ch B9_relationship_othe REB10_8 ///
B11A B10_8 B10_10 B10_11 B10_13 B10_14 B10_15 B10_16 B10_17  B10_18 B10_20 B10_9 B10_5 B10_3 ///
p_objective_health p_health_index c_health_index parental_health_index parental_bad_days_index ///
bullied B11E B12_activities B13_time_spent C7_personality_A	C7_personality_B	C7_personality_C	C7_personality_D	C7_personality_E	C7_personality_F	C7_personality_G	C7_personality_H	C7_personality_I	C7_personality_J	C7_personality_K	C7_personality_L	C7_personality_M	C7_personality_N	C7_personality_O	C7_personality_P	C7_personality_Q	C7_personality_R ///

label var 	B11E "My child has several close friends"
label var 	B12_activities "Parent's weekday time with child"
label var 	B13_time_spent "Parent's weekend time with child"

label var bio_parent "relationship with child: biological parent"
label var parent_adopt "relationship with child: adoptive parent"
label var step_parent "relationship with child: step-parent"
label var foster_parent "relationship with child: foster parent"
label var grandparent "relationship with child: grandparent"
label var family_mem "relationship with child: other family member"
label var other_relationship "relationship with child: other non-family member"

label var hisp "Parent is Hispanic"
label var RACE "race/ethnicity of parent"
label var white "Non-hispanic White parent"
label var dad "Parent is male"
label var hhinc "household income, imputed using categories in nominal USD"
label var male "Child is male"
label var age "Child age"
label var weight "Parent sample weight"
label var child_weight "Child sample weight"
label var REB11A "REV coded: My child becomes easily angry at me"
label var REB10_8 "REV coded: 8.	I argue frequently with my child"
label var parent_some "Parent attended college but has less than Bachelor's degree"
label var parent_hs_less "Parent has not attended college"

label var p_objective_health "Parent report of objective measures of child's mental health problems"
label var comp_mental_health "Index of child's mental health"
label var p_health_index "Parent reported: index of child's health"
label var c_health_index "Child reported: index of mental and physical health"

******
***Personality**
*******


foreach  i in C7_personality_A	C7_personality_D	C7_personality_E	C7_personality_H	C7_personality_I	C7_personality_K	C7_personality_O {
gen RE`i'=5 if `i'==1
replace RE`i'=4 if `i'==2
replace RE`i'=3 if `i'==3
replace RE`i'=2 if `i'==4
replace RE`i'=1 if `i'==5
}


egen agreeableness=rowmean(REC7_personality_A C7_personality_B)
egen courage=rowmean(C7_personality_C)
egen conscientiousness=rowmean(REC7_personality_D REC7_personality_E C7_personality_F C7_personality_G)
egen emo_stability=rowmean(REC7_personality_H REC7_personality_I C7_personality_J)
egen extro=rowmean(REC7_personality_K C7_personality_L)
egen openness=rowmean(REC7_personality_O C7_personality_P)
gen fairness=C7_personality_M
gen social_skill=C7_personality_N
gen wisdom=C7_personality_Q
gen smart=C7_personality_R

egen character=rowmean(fairness social_skill wisdom smart courage)
label var character "cardinal virtues"
egen big5=rowmean(agreeableness conscientiousness emo_stability extro openness)
label var big5 "Desirable scores on Big 5 personality traits"

label var agreeableness "youth reported characteristics: agreeableness"
label var conscientiousness "youth reported characteristics: conscientiousness"
label var courage "youth reported characteristics:  courage"
label var emo_stability  "youth reported characteristics:  emotional stability"
label var extro  "youth reported characteristics: extroversion"
label var fairness  "youth reported characteristics: fairness"
label var openness  "youth reported characteristics: openness to experience"
label var smart  "youth reported characteristics: intelligent"
label var social_skill  "youth reported characteristics: people like to be around me"
label var parental_bad_days_index "index of parental health from bad days items"
label var parental_health_index "index of parental health from several items"
label var wisdom "youth reported characteristics: wisdom"

aorder
save "[YOUR PARENT FOLDER]\replication_file\Gallup_Family_Adolescent_Health_2023_Replication_File.dta", replace

cd "${base}\output_files"
log using "Codebook.txt", replace text
codebook 
log close